<?php
/**
 * 数据库数据资源
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Db.php 1059 2011-11-18 09:26:15Z mmxie $
 */
class IG_Data_Source_Db extends IG_Data_Source
{

    private $_db;
    private $_statement;
    private $_config;

    protected $_query;

    public function getData()
    {
        return $this->_data;
    }

    public function setQuery($query)
    {
        $this->_query = $query;
    }

    public function getQuery()
    {
        return $this->_query;
    }

    public function getMeta()
    {
        if (is_null($this->_meta)) {
            $i = 0;
            $count = $this->_statement->columnCount();
            while ($i < $count) {
                $meta = $this->_statement->getColumnMeta($i);
                $this->_meta[] = $meta['name'];
                $i++;
            }
        }

        return $this->_meta;
    }

    public function run()
    {
        $this->_statement = $this->_db->prepare($this->getQuery());
        $this->_statement->execute();
        $this->_data = $this->_statement->fetchAll();
    }
}